#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json

import pika as pika

if __name__ == '__main__':
    print('rabbitMq test')
    credentials = pika.PlainCredentials('guest', 'guest')  # mq用户名和密码
    connection = pika.BlockingConnection(
        pika.ConnectionParameters(host='localhost', port=5672, virtual_host='/', credentials=credentials))
    channel = connection.channel()
    result = channel.queue_declare(queue='rabbit-test')
    for i in range(100):
        message = json.dumps({'OrderId': "1000%s" % i})
        # 向队列插入数值 routing_key是队列名
        channel.basic_publish(exchange='', routing_key='rabbit-test', body=message)
        print(message)
    connection.close()
